package de.bbl.android.adapter.DataCenter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import de.bbl.android.R;
import de.bbl.android.classes.PlayDay;

public class DataCenterSpieltagArrayAdapter extends ArrayAdapter<PlayDay> {

	private final Activity context;
	private final PlayDay[] values;
	private String competitionId = "1";

	static class ViewHolder {
		public TextView Playday;
		public TextView Playday_Date;
	}
	
	public DataCenterSpieltagArrayAdapter(Activity context, PlayDay[] values) {
		super(context, R.layout.row_layout_datacenter_spieltag, android.R.id.text1, values);
		this.context = context;
		this.values = values;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		String spieltagText = "Spieltag ";
		
		if (getCompetitionId().equals("2"))
			spieltagText = "Playoff Viertelfinale ";
		else if (getCompetitionId().equals("3"))
			spieltagText = "Playoff Halbfinale ";
		else if (getCompetitionId().equals("4"))
			spieltagText = "Playoff Finale ";
			
		View rowView = convertView;
		if (rowView == null) {
			LayoutInflater inflater = context.getLayoutInflater();
			rowView = inflater.inflate(R.layout.row_layout_datacenter_spieltag, null);
			ViewHolder viewHolder = new ViewHolder();
			viewHolder.Playday = (TextView) rowView.findViewById(R.id.textView_spieltag_spieltag);
			viewHolder.Playday_Date = (TextView) rowView.findViewById(R.id.textView_spieltag_datum);
			rowView.setTag(viewHolder);
		}

		ViewHolder holder = (ViewHolder) rowView.getTag();
		holder.Playday.setText(spieltagText + values[position].getPlayDayNumber() + ".");
		holder.Playday_Date.setText(values[position].getPlayDayDateFrom() + " - " + values[position].getPlayDayDateTil());

		return rowView;
	}

	public String getCompetitionId() {
		return competitionId;
	}

	public void setCompetitionId(String competitionId) {
		this.competitionId = competitionId;
	}

}
